//
//  MyHeaderView.m
//  Router
//
//  Created by teki on 15/10/15.
//  Copyright © 2015年 dc. All rights reserved.
//

#import "MyHeaderView.h"
#import "UserModel.h"

@interface MyHeaderView ()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UILabel *phoneLabel;

@end

@implementation MyHeaderView
- (instancetype)init{
    if (self = [super init])
    {
        [self initUI];
    }
    return self;

}


-(id)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
       
        [self initUI];
    }
    return self;
}


- (void)initUI
{
    UIFont *namelabelFont = [UIFont systemFontOfSize:16];
    UIFont *phonelabelFont = [UIFont systemFontOfSize:14];
    self.backgroundColor = [UIColor colorWithHexString:@"#e1f6de"];
    
    self.imgView = [UIImageView new];
    self.imgView.translatesAutoresizingMaskIntoConstraints = NO;
    [self addSubview:self.imgView];
    [self.imgView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).offset(18);
        make.centerY.equalTo(self);
        make.size.equalTo(CGSizeMake(37, 37));
    }];
    
    
    self.nameLabel = [self addLabelWithText:@"" font:namelabelFont color:NavgationBarBackgroundColor];
    [self.nameLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.right).offset(11);
        make.centerY.equalTo(self);
    }];
    
    
    self.phoneLabel = [self addLabelWithText:@"" font:phonelabelFont color:NavgationBarBackgroundColor];
    
    [self.phoneLabel makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.right).offset(16);
        make.centerY.equalTo(self);
    }];
}

- (void)setModel:(UserModel *)model
{
    _model = model;
    self.imgView.image = [UIImage imageNamed:@"my_icon"];
    self.nameLabel.text = model.nickName;
    self.phoneLabel.text =  model.userName;
}


- (void)willRemoveSubview:(UIView *)subview
{
    NSLog(@"%s",__func__);
}


- (void)willMoveToSuperview:(UIView *)newSuperview
{
    NSLog(@"%s",__func__);
}


- (void)didMoveToSuperview
{
    NSLog(@"%s",__func__);
}



@end
